﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NHibernate;
using SafeNet.InitialDatabase;
using SafeNet.InitialDatabase.EntityClasses;
using SafeNet.InitialDatabase.Repository;
using NHibernate.Cfg;

namespace SafeNet.Test.Persistence
{
    [TestClass]
    public class UnitTest1
    {/*
        private ISessionFactory _sessionFactory;
        private Configuration _configuration;

        #region repository tests
        [TestMethod]
        public void Can_Save_MessageQueue_using_Repository()
        {
            Configuration _configuration = new Configuration();

            _configuration.Configure();

            _configuration.AddAssembly("SafeNet.InitialDatabase.Model");

            _sessionFactory = _configuration.BuildSessionFactory();
            ISession session = _sessionFactory.GetCurrentSession();
            MessageQueueRepository repo = new MessageQueueRepository(session, session.BeginTransaction());
            MessageQueue mq = new MessageQueue
            {
                ArrivalTime = DateTime.Now,
                Direction = "out",
                GeneratedTime = DateTime.Now,
                InsertTime = DateTime.Now,
                Message = "<poruka>Kako si</poruka>",
                ProcessedTime = DateTime.Now
            };
            repo.Save(mq);
            session.Transaction.Commit();
            session.Close();
            Assert.IsNotNull(mq.MessageId);
         
        }
        #endregion
       */

        #region nhibernate tests

        [TestMethod]
        public void can_get_all_MessageQueues_by_id_using_nhibernate()
        {
            ISession session = SessionManager.OpenSession();
            IList<MessageQueue> mqList = null;
            mqList = session.CreateCriteria<MessageQueue>().List<MessageQueue>();
            Assert.IsNotNull(mqList);
        }
        [TestMethod]
        public void can_get_MessageQueue_by_id_using_nhibernate()
        {
            ISession session = SessionManager.OpenSession();
            MessageQueue mq = session.Get<MessageQueue>(7);
            Assert.AreEqual<int>(7, mq.MessageId);
        }


        [TestMethod]
        public void can_save_MessageQueue_using_nhibernate()
        {
            ISession session = SessionManager.OpenSession();
            MessageQueue mq = new MessageQueue
            {
                ArrivalTime = DateTime.Now,
                Direction = "out",
                GeneratedTime = DateTime.Now,
                InsertTime = DateTime.Now,
                Message = "<poruka>Kako si</poruka>",
                ProcessedTime = DateTime.Now
            };
            session.Save(mq);
            Assert.IsNotNull(mq.MessageId);
        }


        [TestMethod]
        public void can_get_GoodsDeclaration_with_goods_items_using_nhibernate()
        {
            ISession session = SessionManager.OpenSession();
            GoodsDeclaration gd = session.Get<GoodsDeclaration>(2);
            Assert.IsNotNull(gd, "NIJE MOGAO DA DOHVATI IZ BAZE GoodsDeclaration KOJI IMA id=2");
            
        }

        [TestMethod]
        public void can_save_GoodsDeclaration_with_goods_items_using_nhibernate()
        {
            //TODO Napraviti objekat GoodsDeclaration sa vise GoodsItems i snimiti u bazu
            ISession session = SessionManager.OpenSession();
            Assert.Fail("Nije implementiran test");
        }
        #endregion
        
    }
}
